#ifndef OSC_GLOBAL_H
#define OSC_GLOBAL_H

#define OSC_NAMESPACE oscill

#ifdef __cplusplus

#ifndef OSC_NAMESPACE /* user namespace */

#  define OSC_PREPEND_NAMESPACE( name ) ::name
//#  define OSC_USE_PREPEND_NAMESPACE( name )
#  define OSC_USE_NAMESPACE
#  define OSC_BEGIN_NAMESPACE
#  define OSC_END_NAMESPACE
#  define OSC_BEGIN_INCLUDE_NAMESPACE
#  define OSC_END_INCLUDE_NAMESPACE
#  define OSC_FORWARD_DECLARE_CLASS( name ) class name;
#  define OSC_FORWARD_DECLARE_STRUCT( name ) struct name;
#  define OSC_MANGLE_NAMESPACE( name ) name
#  define OSC_BEGIN_MODULE( x )
#  define OSC_END_MODULE( x )
#  define OSC_USE_MODULE( x )

#else /* user namespace */

#  define OSC_PREPEND_NAMESPACE( name ) ::OSC_NAMESPACE::name
//#  define OSC_USE_PREPEND_NAMESPACE( name ) using namespace OSC_PREPEND_NAMESPACE( name );
#  define OSC_USE_NAMESPACE using namespace ::OSC_NAMESPACE;
#  define OSC_BEGIN_NAMESPACE namespace OSC_NAMESPACE {
#  define OSC_END_NAMESPACE }
#  define OSC_BEGIN_INCLUDE_NAMESPACE }
#  define OSC_END_INCLUDE_NAMESPACE namespace OSC_NAMESPACE {

#  define OSC_FORWARD_DECLARE_CLASS( name ) \
    OSC_BEGIN_NAMESPACE class name; OSC_END_NAMESPACE \
    using OSC_PREPEND_NAMESPACE( name );

#  define OSC_FORWARD_DECLARE_STRUCT( name ) \
    OSC_BEGIN_NAMESPACE struct name; OSC_END_NAMESPACE \
    using OSC_PREPEND_NAMESPACE( name );

#  define OSC_MANGLE_NAMESPACE0( x ) x
#  define OSC_MANGLE_NAMESPACE1( a, b ) a##_##b
#  define OSC_MANGLE_NAMESPACE2( a, b ) OSC_MANGLE_NAMESPACE1(a,b)
#  define OSC_MANGLE_NAMESPACE( name ) OSC_MANGLE_NAMESPACE2( \
        OSC_MANGLE_NAMESPACE0( name ), OSC_MANGLE_NAMESPACE0( OSC_NAMESPACE ) )

namespace OSC_NAMESPACE {}

#  ifndef OSC_NO_USING_NAMESPACE
   /*
    This expands to a "using OSC_NAMESPACE" also in _header files_.
    It is the only way the feature can be used without too much
    pain, but if people _really_ do not want it they can add
    DEFINES += OSC_NO_USING_NAMESPACE to their project files.
    */
   OSC_USE_NAMESPACE
#  endif

#  define OSC_BEGIN_MODULE( name ) namespace name {
#  define OSC_END_MODULE( name ) }
#  define OSC_USE_MODULE( name ) using namespace OSC_PREPEND_NAMESPACE( name );

#endif /* user namespace */

#else /* __cplusplus */

#  define OSC_BEGIN_NAMESPACE
#  define OSC_END_NAMESPACE
#  define OSC_USE_NAMESPACE
#  define OSC_BEGIN_INCLUDE_NAMESPACE
#  define OSC_END_INCLUDE_NAMESPACE
#  define OSC_BEGIN_MODULE( x )
#  define OSC_END_MODULE( x )
#  define OSC_USE_MODULE( x )

#endif /* __cplusplus */

#if defined( OSC_BOOST_CONTAINER )
# include <boost/container/map.hpp>
# include <boost/container/string.hpp>
# include <boost/container/vector.hpp>
  using namespace boost::container;
# if defined( OSC_BOOST_INTRUSIVE )
#  include <boost/intrusive/list.hpp>
   using namespace boost::intrusive;
# else
#  include <boost/container/list.hpp>
# endif
#else
# include <list>
# include <map>
# include <string>
# include <vector>
  using namespace std;
#endif

#define OSC_USE_CONTAINER   using namespace

/*
   The operating system, must be one of: (OSC_OS_x)

     DARWIN   - Darwin OS (synonym for OSC_OS_MAC)
     WIN32    - Win32 (Windows 2000/XP/Vista/7 and Windows Server 2003/2008)
     WINCE    - WinCE (Windows CE 5.0)
     CYGWIN   - Cygwin
     SOLARIS  - Sun Solaris
     LINUX    - Linux
     FREEBSD  - FreeBSD
     NETBSD   - NetBSD
     OPENBSD  - OpenBSD
     BSDI     - BSD/OS
     IRIX     - SGI Irix
     OSF      - HP Tru64 UNIX
     SCO      - SCO OpenServer 5
     UNIXWARE - UnixWare 7, Open UNIX 8
     AIX      - AIX
     HURD     - GNU Hurd
     DGUX     - DG/UX
     RELIANT  - Reliant UNIX
     DYNIX    - DYNIX/ptx
     QNX      - QNX
     QNX6     - QNX RTP 6.1
     LYNX     - LynxOS
     BSD4     - Any BSD 4.4 system
     UNIX     - Any UNIX BSD/SYSV system
*/
#if defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__) || defined(__xlc__))
#  define OSC_OS_DARWIN
#  define OSC_OS_BSD4
#  ifdef __LP64__
#    define OSC_OS_DARWIN64
#  else
#    define OSC_OS_DARWIN32
#  endif
#elif defined(__CYGWIN__)
#  define OSC_OS_CYGWIN
#elif !defined(SAG_COM) && (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))
#  define OSC_OS_WIN32
#  define OSC_OS_WIN64
#elif !defined(SAG_COM) && (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__))
#  if defined(WINCE) || defined(_WIN32_WCE)
#    define OSC_OS_WINCE
#  else
#    define OSC_OS_WIN32
#  endif
#elif defined(__MWERKS__) && defined(__INTEL__)
#  define OSC_OS_WIN32
#elif defined(__sun) || defined(sun)
#  define OSC_OS_SOLARIS
#elif defined(__linux__) || defined(__linux)
#  define OSC_OS_LINUX
#elif defined(__FreeBSD__) || defined(__DragonFly__)
#  define OSC_OS_FREEBSD
#  define OSC_OS_BSD4
#elif defined(__NetBSD__)
#  define OSC_OS_NETBSD
#  define OSC_OS_BSD4
#elif defined(__OpenBSD__)
#  define OSC_OS_OPENBSD
#  define OSC_OS_BSD4
#elif defined(__bsdi__)
#  define OSC_OS_BSDI
#  define OSC_OS_BSD4
#elif defined(__Lynx__)
#  define OSC_OS_LYNX
#elif defined(__GNU__)
#  define OSC_OS_HURD
#elif defined(__DGUX__)
#  define OSC_OS_DGUX
#elif defined(__QNXNTO__)
#  define OSC_OS_QNX
#elif defined(_SEQUENT_)
#  define OSC_OS_DYNIX
#elif defined(__USLC__) /* all SCO platforms + UDK or OUDK */
#  define OSC_OS_UNIXWARE
#elif defined(__svr4__) && defined(i386) /* Open UNIX 8 + GCC */
#  define OSC_OS_UNIXWARE
#else
#  error "Libs has not been ported to this OS - talk to pirskij@gmail.com"
#endif

#if defined(OSC_OS_WIN32) || defined(OSC_OS_WIN64) || defined(OSC_OS_WINCE)
#  define OSC_OS_WIN
#endif

#if defined(OSC_OS_DARWIN)
#  define OSC_OS_MAC /* OSC_OS_MAC is mostly for compatibility, but also more clear */
#  define OSC_OS_MACX /* OSC_OS_MACX is only for compatibility.*/
#  if defined(OSC_OS_DARWIN64)
#     define OSC_OS_MAC64
#  elif defined(OSC_OS_DARWIN32)
#     define OSC_OS_MAC32
#  endif
#endif

#ifdef OSC_AUTODETECT_COCOA
#  ifdef OSC_OS_MAC64
#    define OSC_MAC_USE_COCOA 1
#    define OSC_BUILD_KEY OSC_BUILD_KEY_COCOA
#  else
#    define OSC_BUILD_KEY OSC_BUILD_KEY_CARBON
#  endif
#endif

#if defined(OSC_OS_MAC64) && !defined(OSC_MAC_USE_COCOA)
#error "You are building a 64-bit application, but using a 32-bit version of LIBS. Check your build configuration."
#endif

#if defined(OSC_OS_WIN)
#  undef OSC_OS_UNIX
#elif !defined(OSC_OS_UNIX)
#  define OSC_OS_UNIX
#endif

#if defined(OSC_OS_DARWIN) && !defined(OSC_LARGEFILE_SUPPORT)
#  define OSC_LARGEFILE_SUPPORT 64
#endif

#ifdef OSC_OS_DARWIN
#  ifdef MAC_OS_X_VERSION_MIN_REQUIRED
#    undef MAC_OS_X_VERSION_MIN_REQUIRED
#  endif
#  define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_4
#  include <AvailabilityMacros.h>
#  if !defined(MAC_OS_X_VERSION_10_3)
#     define MAC_OS_X_VERSION_10_3 MAC_OS_X_VERSION_10_2 + 1
#  endif
#  if !defined(MAC_OS_X_VERSION_10_4)
#       define MAC_OS_X_VERSION_10_4 MAC_OS_X_VERSION_10_3 + 1
#  endif
#  if !defined(MAC_OS_X_VERSION_10_5)
#       define MAC_OS_X_VERSION_10_5 MAC_OS_X_VERSION_10_4 + 1
#  endif
#  if !defined(MAC_OS_X_VERSION_10_6)
#       define MAC_OS_X_VERSION_10_6 MAC_OS_X_VERSION_10_5 + 1
#  endif
#  if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6)
#    warning "This version of Mac OS X is unsupported"
#  endif
#endif

/*
   The compiler, must be one of: (OSC_CC_x)

     MSVC     - Microsoft Visual C/C++, Intel C++ for Windows
     BOR      - Borland/Turbo C++
     GNU      - GNU C++
     INTEL    - Intel C++ for Linux, Intel C++ for Windows

   Should be sorted most to least authoritative.
*/

#if defined(_MSC_VER)
#  define OSC_CC_MSVC	//!< Defined if the application is compiled using Microsoft Visual C/C++, Intel C++ for Windows.
/* proper support of bool for _MSC_VER >= 1100 */
#  define OSC_CANNOT_DELETE_CONSTANT
#  define OSC_OUTOFLINE_TEMPLATE inline typename
#  define OSC_NO_TEMPLATE_FRIENDS
#  define OSC_NO_PARTIAL_TEMPLATE_SPECIALIZATION
#  define OSC_ALIGNOF(type)   __alignof(type)
#  define OSC_DECL_ALIGN(n)   __declspec(align(n))

/* Visual C++.Net issues for _MSC_VER >= 1300 */
#  if _MSC_VER >= 1300
//#    define sprintf	sprintf_s
//#    define strcat	strcat_s
#    define snprintf _snprintf_s
#    define OSC_CC_MSVC_NET	//!< Defined if the application is compiled using Microsoft Visual C/C++, Intel C++ for Windows.
#    if _MSC_VER < 1310 || (defined(OSC_OS_WIN64) && defined(_M_IA64))
#      define OSC_TYPENAME
#    else
#      undef OSC_NO_PARTIAL_TEMPLATE_SPECIALIZATION
#    endif
#  else
#    define OSC_NO_USING_KEYWORD
#    define OSC_NO_MEMBER_TEMPLATES
#  endif
#  if _MSC_VER < 1310
#     define OSC_NO_QOBJECT_CHECK
#     define OSC_TYPENAME
#     define OSC_NO_TEMPLATE_TEMPLATE_PARAMETERS
#  endif
/* Intel C++ disguising as Visual C++: the `using' keyword avoids warnings */
#  if defined(__INTEL_COMPILER)
#    define OSC_CC_INTEL	//!< Defined if the application is compiled using Intel C++ for Linux, Intel C++ for Windows
#  endif
/* MSVC does not support SSE/MMX on x64 */
#  if (defined(OSC_CC_MSVC) && defined(_M_X64))
#    undef OSC_HAVE_SSE
#    undef OSC_HAVE_MMX
#    undef OSC_HAVE_3DNOW
#  endif

#elif defined(__BORLANDC__) || defined(__TURBOC__)
#  define OSC_CC_BOR	//!< Defined if the application is compiled using Borland/Turbo C++.
#  define OSC_INLINE_TEMPLATE
#  if __BORLANDC__ < 0x502
#    define OSC_NO_BOOL_TYPE
#    define OSC_NO_EXPLICIT_KEYWORD
#  endif
#  define OSC_NO_USING_KEYWORD

#elif defined(__GNUC__)
#  define OSC_CC_GNU //!< Defined if the application is compiled using GNU C++.
#  define OSC_C_CALLBACKS
#  if defined(__MINGW32__)
#    define OSC_CC_MINGW
#  endif
#  if defined(__INTEL_COMPILER)
/* Intel C++ also masquerades as GCC 3.2.0 */
#    define OSC_CC_INTEL //!< Defined if the application is compiled using Intel C++ for Linux, Intel C++ for Windows
#    define OSC_NO_TEMPLATE_FRIENDS
#  endif
#  if __GNUC__ == 2 && __GNUC_MINOR__ <= 7
#    define OSC_FULL_TEMPLATE_INSTANTIATION
#  endif
/* GCC 2.95 knows "using" but does not support it correctly */
#  if __GNUC__ == 2 && __GNUC_MINOR__ <= 95
#    define OSC_NO_USING_KEYWORD
#    define OSC_NO_STL_WCHAR
#  endif
#  if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
#    define OSC_ALIGNOF(type)   __alignof__(type)
#    define OSC_TYPEOF(expr)    __typeof__(expr)
#    define OSC_DECL_ALIGN(n)   __attribute__((__aligned__(n)))
#  endif
/* GCC <= 3.3 cannot handle template friends */
#  if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ <= 3)
#    define OSC_NO_TEMPLATE_FRIENDS
#  endif
#  if (defined(OSC_CC_GNU) || defined(OSC_CC_INTEL))
#    define OSC_PACKED __attribute__ ((__packed__))
#    define OSC_NO_PACKED_REFERENCE
#  endif

#else
#  error "Program has not been tested with this compiler - talk to pirskij@gmail.com"
#endif

#if (defined(OSC_CC_GNU) && !defined(OSC_CC_INTEL) && (__GNUC__ - 0 > 3 || (__GNUC__ - 0 == 3 && __GNUC_MINOR__ - 0 >= 2))) || defined(OSC_CC_RVCT)
#  define OSC_DECL_DEPRECATED __attribute__ ((__deprecated__))
#elif defined(OSC_CC_MSVC) && (_MSC_VER >= 1300)
#  define OSC_DECL_DEPRECATED __declspec(deprecated)
#  if defined (OSC_CC_INTEL)
#    define OSC_DECL_VARIABLE_DEPRECATED
#  else
#  endif
#else
#  define OSC_DECL_DEPRECATED
#endif


#if defined(OSC_OS_MAC) && !defined(OSC_CC_INTEL)
#  define OSC_BEGIN_HEADER extern "C++" {
#  define OSC_END_HEADER }
#  define OSC_BEGIN_INCLUDE_HEADER }
#  define OSC_END_INCLUDE_HEADER extern "C++" {
#else
#  define OSC_BEGIN_HEADER
#  define OSC_END_HEADER
#  define OSC_BEGIN_INCLUDE_HEADER
#  define OSC_END_INCLUDE_HEADER extern "C++"
#endif


OSC_BEGIN_HEADER
OSC_BEGIN_NAMESPACE


#define OSC_API	__stdcall

#define OSC_STATUS_SUCCESS	0
#define OSC_STATUS_ERROR	-1

#ifndef OSC_DECL_EXPORT
#  if defined(OSC_OS_WIN)
#    define OSC_DECL_EXPORT __declspec( dllexport )
#  elif defined(OSC_VISIBILITY_AVAILABLE)
#    define OSC_DECL_EXPORT __attribute__((visibility("default")))
#  endif
#  ifndef OSC_DECL_EXPORT
#    define OSC_DECL_EXPORT
#  endif
#endif
#ifndef OSC_DECL_IMPORT
#  if defined(OSC_OS_WIN)
#    define OSC_DECL_IMPORT __declspec(dllimport)
#  else
#    define OSC_DECL_IMPORT
#  endif
#endif


/*
   Some classes do not permit copies to be made of an object. These
   classes contains a private copy constructor and assignment
   operator to disable copying (the compiler gives an error message).
*/
#define OSC_DISABLE_COPY( Class ) \
    Class(const Class &); \
    Class &operator=(const Class &);


/* Unsigned data types. */
typedef unsigned char      oscByte;     //!< Typedef for \c unsigned \c char. Useful for manipulation with Byte data.
typedef unsigned char      oscUInt8;    //!< Typedef for \c unsigned \c char. This type is guaranteed to be 8-bit on all supported platforms.
typedef unsigned short     oscUInt16;   //!< Typedef for \c unsigned \c short. This type is guaranteed to be 16-bit on all supported platforms.
typedef unsigned short     oscWord;     //!< Typedef for \c unsigned \c short. This type is guaranteed to be 16-bit on all supported platforms.
typedef unsigned int       oscUInt32;   //!< Typedef for \c unsigned \c int. This type is guaranteed to be 32-bit on all supported platforms.
typedef unsigned int       oscDWord;    //!< Typedef for \c unsigned \c int. This type is guaranteed to be 32-bit on all supported platforms.
#if defined(OSC_OS_WIN) && !defined(OSC_CC_GNU)
    typedef unsigned __int64 oscUInt64;	//!< Typedef for \c unsigned \c __int64. This type is guaranteed to be 64-bit on all supported platforms.
#else
    typedef unsigned long long oscUInt64;	//!< Typedef for \c unsigned \c long \c long \c int. This type is guaranteed to be 64-bit on all supported platforms.
#endif
typedef unsigned char      oscUChar;    //!< Convenience typedef for \c unsigned \c char.
typedef unsigned short     oscUShort;   //!< Convenience typedef for \c unsigned \c short.
typedef unsigned int       oscUInt;     //!< Convenience typedef for \c unsigned \c int.
typedef unsigned long      oscULong;    //!< Convenience typedef for \c unsigned \c long.
#if defined(OSC_OS_WIN) && !defined(OSC_CC_GNU)
    typedef unsigned __int64 oscULongLong;	//!< Typedef for \c unsigned \c __int64. This is the same as oscUInt64.
#else
    typedef unsigned long long oscULongLong;	//!< Typedef for \c unsigned \c long \c long \c int. This is the same as oscUInt64.
#endif
typedef size_t             oscSizeT;    //!< Convenience typedef for \c size_t.

/* Signed data types. */
typedef char               oscChar;     //!< Convenience typedef for \c signed \c char.
typedef char               oscInt8;     //!< Typedef for \c signed \c char. This type is guaranteed to be 8-bit on all supported platforms.
typedef short              oscInt16;    //!< Typedef for \c signed \c short. This type is guaranteed to be 16-bit on all supported platforms.
typedef int                oscInt32;    //!< Typedef for \c signed \c short. This type is guaranteed to be 32-bit on all supported platforms.
#if defined(OSC_OS_WIN) && !defined(OSC_CC_GNU)
    typedef __int64        oscInt64;    //!< Typedef for \c signed \c __int64. This type is guaranteed to be 64-bit on all supported platforms.
#else
    typedef long long      oscInt64;    //!< Typedef for \c signed \c long \c long \c int. This type is guaranteed to be 64-bit on all supported platforms.
#endif
typedef short              oscShort;	//!< Convenience typedef for \c signed \c short.
typedef long               oscLong;		//!< Convenience typedef for \c signed \c long.
#if defined(OSC_OS_WIN) && !defined(OSC_CC_GNU)
    typedef __int64        oscLongLong;	//!< Typedef for \c signed \c __int64. This is the same as oscInt64.
#else
    typedef long long      oscLongLong;		//!< Typedef for \c signed \c long \c long \c int. This is the same as oscInt64.
#endif

/* Floating point data types. */
typedef float              oscFloat;	//!< Typedef for \c float.
typedef double             oscDouble;	//!< Typedef for \c double.
#if defined(OSC_NO_FPU) || defined(OSC_ARCH_ARM) || defined(OSC_ARCH_WINDOWSCE)
typedef float             oscReal;		//!< Typedef for \c float on all platforms.
#else
typedef double             oscReal;		//!< Typedef for \c double on all platforms.
#endif

/* Additional data types. */
typedef void               oscVoid;	//!< Typedef for \c void.
typedef oscByte*           oscPtr;	//!< Typedef for pointer.
typedef char*              oscCharPtr;	//!< Typedef for \c char pointer.

#if defined( OSC_OS_WIN ) && !defined( OSC_CC_GNU )
#   define OSC_INT64_C( c ) c ## i64    //!< signed 64 bit constant.
#   define OSC_UINT64_C( c ) c ## ui64   //!< unsigned 64 bit constant.
#else
#   define OSC_INT64_C( c ) static_cast<long long>( c ## LL )     //!< signed 64 bit constant.
#   define OSC_UINT64_C( c ) static_cast<unsigned long long>( c ## ULL ) //!< unsigned 64 bit constant.
#endif

#ifndef OSC_POINTER_SIZE
#  if defined(OSC_OS_WIN64)
#    define OSC_POINTER_SIZE 8	//!< Expands to the size of a pointer in bytes. This is equivalent to \c sizeof(void \c *) but can be used in a preprocessor directive.
#  elif defined(OSC_OS_WIN32) || defined(OSC_OS_WINCE)
#    define OSC_POINTER_SIZE 4	//!< Expands to the size of a pointer in bytes. This is equivalent to \c sizeof(void \c *) but can be used in a preprocessor directive.
#  endif
#endif

#if defined(OSC_OS_WIN)
OSC_BEGIN_INCLUDE_NAMESPACE
  #include <windows.h>
  typedef HANDLE           oscHandle;	//!< Typedef for \c HANDLE.
OSC_END_INCLUDE_NAMESPACE
#else
  typedef oscVoid*         oscHandle;	//!< Typedef for \c oscVoid*.
  #define Sleep( msec )    usleep( msec * 1000 )
#endif

/* Boolean data type. */
#if defined(OSC_NO_BOOL_TYPE)
    typedef char           oscBool;	//!< Typedef for \c char.
#else
    typedef bool           oscBool;	//!< Typedef for \c bool.
#endif

OSC_BEGIN_INCLUDE_NAMESPACE
/* Useful types. */
typedef unsigned char      uchar;	//!< Convenience typedef for \c unsigned \c char.
typedef unsigned short     ushort;	//!< Convenience typedef for \c unsigned \c short.
typedef unsigned int       uint;	//!< Convenience typedef for \c unsigned \c int.
typedef unsigned long      ulong;	//!< Convenience typedef for \c unsigned \c long.
OSC_END_INCLUDE_NAMESPACE

#ifndef TRUE
# define TRUE true //!< Synonym for \c true. \see FALSE
# define FALSE false	//!< Synonym for \c false. \see TRUE
#endif

template <oscInt32> struct OscIntegerForSize;
template <>    struct OscIntegerForSize<1> { typedef oscUInt8  Unsigned; typedef oscInt8  Signed; };
template <>    struct OscIntegerForSize<2> { typedef oscUInt16 Unsigned; typedef oscInt16 Signed; };
template <>    struct OscIntegerForSize<4> { typedef oscUInt32 Unsigned; typedef oscInt32 Signed; };
template <>    struct OscIntegerForSize<8> { typedef oscUInt64 Unsigned; typedef oscInt64 Signed; };
template <class T> struct OscIntegerForSizeof: OscIntegerForSize<sizeof(T)> { };
typedef OscIntegerForSizeof<void*>::Unsigned oscUIntPtr;
typedef OscIntegerForSizeof<void*>::Signed oscPtrDiff;

typedef int OscNoImplicitBoolCast;


inline oscUInt64 oClockUSec()
{
#if defined( OSC_OS_WIN )
    LARGE_INTEGER liPerfFreq;
    LARGE_INTEGER liPerfNow;
    QueryPerformanceFrequency( &liPerfFreq );
    QueryPerformanceCounter( &liPerfNow );
    return ( oscUInt64 ) ( ( ( ( double ) liPerfNow.QuadPart) * ( double ) 1000000.0 ) /
                               ( double ) liPerfFreq.QuadPart );
#else
    timeval now;
    gettimeofday( &now, NULL );
    return ( oscUInt64 )( ( oscUInt64 ) now.tv_sec ) * 1000000ULL +
                          ( oscUInt64 ) now.tv_usec  * 1ULL;
#endif
}

#define OSC_GET_CUR_TIME_USEC   oClockUSec()
#define OSC_IS_TIMEOUT( startTimeVal, timeOutVal ) \
    ( ( (oscUInt64) OSC_GET_CUR_TIME_USEC - (oscUInt64) startTimeVal ) >= (oscUInt64) timeOutVal )

/* Macros inform, that do nothing */
#define OscDoNothing()

inline void OscNoop() {}

/* These wrap try/catch so we can switch off exceptions later.

   Beware - do not use more than one OSC_CATCH per OSC_TRY, and do not use
   the exception instance in the catch block.
   If you can't live with those constraints, don't use these macros.
   Use the OSC_NO_EXCEPTIONS macro to protect your code instead.
*/

#if !defined(OSC_NO_EXCEPTIONS) && defined(OSC_CC_GNU) && !defined (__EXCEPTIONS)
#  define OSC_NO_EXCEPTIONS
#endif

#ifdef OSC_NO_EXCEPTIONS
#  define OSC_TRY if ( true )
#  define OSC_CATCH(A) else
#  define OSC_THROW(A) OscNoop()
#  define OSC_RETHROW OscNoop()
#else
#  define OSC_TRY try
#  define OSC_CATCH(A) catch ( A )
#  define OSC_THROW(A) throw A
#  define OSC_RETHROW throw
#endif


#ifndef OSC_OUTOFLINE_TEMPLATE
#  define OSC_OUTOFLINE_TEMPLATE
#endif
#ifndef OSC_INLINE_TEMPLATE
#  define OSC_INLINE_TEMPLATE inline
#endif

#ifndef OSC_TYPENAME
#  define OSC_TYPENAME typename
#endif

template <typename T>
inline const T &oMin(const T &a, const T &b) { return (a < b) ? a : b; }
template <typename T>
inline const T &oMax(const T &a, const T &b) { return (a < b) ? b : a; }
template <typename T>
inline const T &oBound(const T &min, const T &val, const T &max)
{ return oMax(min, oMin(max, val)); }

/*
   Avoid "unused parameter" warnings
 */

#if defined(OSC_CC_INTEL) && !defined(OSC_OS_WIN) || defined(OSC_CC_RVCT)
template <typename T>
inline void oUnused( T &x ) { (void)x; }
#  define OSC_UNUSED(x) oUnused(x);
#else
#  define OSC_UNUSED(x) (void)x;
#endif


OSC_END_NAMESPACE
OSC_END_HEADER


#endif // OSC_GLOBAL_H
